# -*- coding: utf-8 -*-

from sqlalchemy import MetaData
from flask import url_for, request, session
from flask_sqlalchemy import SQLAlchemy
from flask_redis import FlaskRedis
from flask_babelex import Babel
from flask_admin import Admin
# from flask_compress import Compress
# from flask_socketio import SocketIO, emit, send


metadata = MetaData(
    naming_convention={
        "ix": "ix_%(column_0_label)s",
        "uq": "uq_%(table_name)s_%(column_0_name)s",
        "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
        "pk": "pk_%(table_name)s",
    }
)


db = SQLAlchemy(metadata=metadata)
# compress = Compress()
redis_store = FlaskRedis()
# socketio = SocketIO(async_mode=None, server='127.0.0.1')
from adminApp.views.myadminindexview import MyAdminIndexView
admin = Admin(name='设备管理', url='/', index_view=MyAdminIndexView(url='/'), base_template='my_master.html', template_mode='bootstrap3')
# admin = Admin(name='设备管理', url='/', base_template='my_master.html', template_mode='bootstrap3')

babel = Babel()

@babel.localeselector
def get_locale():
    override = request.args.get('lang')

    if override:
        session['lang'] = override

    return session.get('lang', 'zh_CN')
